<?php

namespace App\Admin\Forms;

use DB;
use Dcat\Admin\Widgets\Form;
use Symfony\Component\HttpFoundation\Response;

class Setting extends Form
{
    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return Response
     */
    public function handle(array $input)
    {

        //dd(DB::table('systems')->first());

        $query = DB::table('systems')->where('id', 1)->update(['exchange_rate' => number_format($input['exchange_rate'],2)]);

        // return $this->error('Your error message.');

        return $this->success('设置成功.', '/exchage_rate');
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->text('exchange_rate', '汇率')->help('（必须是数字，小数点后最多2位）')->rules('numeric')->required();
    }

    /**
     * The data of the form.
     *
     * @return array
     */
    public function default()
    {
        $val = DB::table('systems')->where('id', 1)->get();

        return [
            'exchange_rate'  => $val[0]->exchange_rate
        ];
    }
}
